home *** CD-ROM | disk | FTP | other *** search
- #include <Types.h>
- #include <Files.h>
- #include <Devices.h>
- #include <Quickdraw.h>
- #include <OSUtils.h>
- #include <CType.h>
- #include <Dialogs.h>
- #include <Desk.h>
- #include <Icons.h>
- #include <Errors.h>
- #include <Resources.h>
- #include <Lists.h>
- #include <Memory.h>
- #include <SysEqu.h>
- #include <OSEvents.h>
- #include <Packages.h>
- #include <ToolUtils.h>
- #include <StdIO.h>
- #include <String.h>
- #include <Fonts.h>
- #include <GestaltEqu.h>
- #include <Menus.h>
- #include <Sound.h>
- #include <Traps.h>
- #include <Windows.h>
- #include <Quickdraw.h>
-
- #define Rez
- #include "privileges.h"
-
- ControlHandle vScrollH;
- TEHandle infoTEH;
-
- pascal Boolean infoFilter(DialogPtr ,EventRecord *,short *);
-
- short
- calcNumVisibleLines(TEHandle theTEH,short startLine)
- {
- Rect box;
- short lineHeight,nLines,numLines=0;
-
- box=(**theTEH).destRect;
- lineHeight=(**theTEH).lineHeight;
- nLines=(**theTEH).nLines;
- while( true ) {
- if (startLine > nLines) break;
- if (lineHeight==-1) {
- box.top+=TEGetHeight((long)startLine,(long)startLine,theTEH);
- }
- else {
- box.top+=lineHeight;
- }
- if (box.top > box.bottom) break;
- ++startLine;
- ++numLines;
- }
- return(numLines);
- }
-
- void blinkButton(DialogPtr theDialog, short itemNum){
-
- Handle itemH;
- Rect box;
- short itemType;
-
- GetDItem(theDialog,itemNum,&itemType,&itemH,&box);
-
- HiliteControl((ControlHandle)itemH,10 );
- HiliteControl((ControlHandle)itemH, 1 );
- }
-
-
- void
- frameButton(DialogPtr theDialog,short itemNum,short textItem1,short textItem2)
- {
- Handle itemH;
- Rect box;
- Str255 theText;
- short itemType,OKhiliteState=255;
- long pattern[2];
-
- SetPort((GrafPtr)theDialog);
- if (textItem1) {
- pattern[0]=pattern[1]=0xAA55AA55;
- GetDItem(theDialog,textItem1,&itemType,&itemH,&box);
- GetIText(itemH,(void *)&theText);
- if (theText[0]) {
- GetDItem(theDialog,textItem2,&itemType,&itemH,&box);
- GetIText(itemH,(void *)&theText);
- if (theText[0]) {
- OKhiliteState=0;
- pattern[0]=pattern[1]=0xFFFFFFFF;
- }
- }
- GetDItem(theDialog,itemNum,&itemType,&itemH,&box);
- if ((**((ControlHandle)itemH)).contrlHilite != OKhiliteState) {
- HiliteControl((ControlHandle)itemH,OKhiliteState);
- }
- PenPat((void *)&pattern);
- }
- GetDItem(theDialog,ITEM_OK,&itemType,&itemH,&box);
- InsetRect(&box,-4,-4);
- PenSize(3,3);
- FrameRoundRect(&box,16,16);
- PenNormal();
- }
-
- void
- showInfoDialog()
- {
- DialogPtr theDialog;
- Handle itemH,textH;
- Rect box;
- StScrpHandle styleH=NULL;
- short itemHit,itemType,numLines;
- long response;
-
- if (theDialog=GetNewDialog( DITL_INFO,0L,(WindowPtr)(-1L))) {
- SetPort((GrafPtr)theDialog);
-
- GetDItem(theDialog,INFO_ITEM,&itemType,&itemH,&box);
- box.right-=15;
- InsetRect(&box,4,4);
-
- if (Gestalt(gestaltTextEditVersion,&response)) response=0L;
- if (response >= gestaltTE1) {
- infoTEH=TEStylNew(&box,&box);
- if (styleH=(StScrpHandle)Get1Resource('styl',TEXT_INFO)) {
- HNoPurge((Handle)styleH);
- MoveHHi((Handle)styleH);
- HLock((Handle)styleH);
- }
- }
- else {
- infoTEH=TENew(&box,&box);
- }
-
- if (infoTEH) {
- if (textH=Get1Resource('TEXT',TEXT_INFO)) {
- HNoPurge(textH);
- MoveHHi(textH);
- HLock(textH);
-
- if (response >= gestaltTE1 && styleH) {
- TEStylInsert(*textH,GetHandleSize(textH),styleH,infoTEH);
- }
- else {
- TESetText(*textH,GetHandleSize(textH),infoTEH);
- }
- TECalText(infoTEH);
- GetDItem(theDialog,INFO_ITEM,&itemType,&itemH,&box);
- box.left=box.right-16;
- numLines=(**infoTEH).nLines-calcNumVisibleLines(infoTEH,1);
- vScrollH=NewControl((WindowPtr)theDialog,&box,"\p",true,1,1,numLines,scrollBarProc,0L);
-
- // centerDialog(theDialog);
- FlushEvents(mDownMask+mUpMask+keyDownMask+keyUpMask,0);
- ShowWindow((WindowPtr)theDialog);
- while ( true ) {
- ModalDialog((void *)infoFilter,&itemHit);
- if (itemHit==ITEM_OK) break;
- }
- }
- TEDispose(infoTEH);
- }
- if (vScrollH) DisposeControl(vScrollH);
- DisposDialog(theDialog);
- }
- }
-
- pascal void
- scrollBarActionProc(ControlHandle theControl,short partCode)
- {
- Rect box;
- short currentVal,lineHeight,numLines;
-
- currentVal=GetCtlValue(theControl);
- switch(partCode) {
- case inUpButton:
- if (currentVal-- > GetCtlMin(theControl)) {
- if ((lineHeight=(**infoTEH).lineHeight)==-1) {
- lineHeight=TEGetHeight((long)currentVal,(long)currentVal,infoTEH);
- }
- SetCtlValue(theControl,currentVal);
- TEScroll(0,lineHeight,infoTEH);
- }
- break;
-
- case inDownButton:
- if (currentVal < GetCtlMax(theControl)) {
- if ((lineHeight=(**infoTEH).lineHeight)==-1) {
- lineHeight=TEGetHeight((long)currentVal,(long)currentVal,infoTEH);
- }
- SetCtlValue(theControl,++currentVal);
- TEScroll(0,-lineHeight,infoTEH);
- }
- break;
-
- case inPageUp:
- numLines=0;
- box=(**infoTEH).destRect;
- while ( true ) {
- if (--currentVal < GetCtlMin(theControl)) break;
- if ((lineHeight=(**infoTEH).lineHeight)==-1) {
- lineHeight=TEGetHeight((long)currentVal,(long)currentVal,infoTEH);
- }
- box.top+=lineHeight;
- if (box.top >= box.bottom) break;
- ++numLines;
- }
- if (numLines>0) {
- currentVal=GetCtlValue(theControl);
- lineHeight=TEGetHeight((long)currentVal-1,(long)currentVal-numLines,infoTEH);
- SetCtlValue(theControl,currentVal-numLines);
- TEScroll(0,lineHeight,infoTEH);
- }
- break;
-
- case inPageDown:
- numLines=0;
- box=(**infoTEH).destRect;
- while ( true ) {
- if (currentVal >= GetCtlMax(theControl)) break;
- if ((lineHeight=(**infoTEH).lineHeight)==-1) {
- lineHeight=TEGetHeight((long)currentVal,(long)currentVal,infoTEH);
- }
- box.top+=lineHeight;
- if (box.top >= box.bottom) break;
- ++currentVal;
- ++numLines;
- }
- if (numLines>0) {
- currentVal=GetCtlValue(theControl);
- lineHeight=TEGetHeight((long)currentVal+numLines-1,(long)currentVal,infoTEH);
- SetCtlValue(theControl,currentVal+numLines);
- TEScroll(0,-lineHeight,infoTEH);
- }
- break;
- }
- }
-
- void
- scrollDelta(ControlHandle theControl,short startVal,short delta)
- {
- short lineHeight;
-
- if (delta && theControl) {
- if (delta>0) {
- lineHeight=-TEGetHeight((long)startVal+delta-1,(long)startVal,infoTEH);
- }
- else {
- lineHeight=TEGetHeight((long)startVal-1,(long)startVal+delta,infoTEH);
- }
- TEScroll(0,lineHeight,infoTEH);
- }
- }
-
-
- pascal Boolean
- infoFilter(DialogPtr theDialog,EventRecord *theEvent,short *itemHit)
- {
- Boolean retVal=false;
- Handle itemH;
- Point where;
- Rect box;
- short delta,itemType,newVal,partCode,val;
- unsigned short key,vKey;
-
- SetPort((GrafPtr)theDialog);
- switch(theEvent->what) {
- case autoKey:
- case keyDown:
- key=(unsigned short)(theEvent->message & charCodeMask);
- vKey=(unsigned short)((theEvent->message & keyCodeMask) >> 8);
-
- if (vKey==ENTER_KEY || vKey==RETURN_KEY) {
- blinkButton(theDialog,ITEM_OK);
- *itemHit=ITEM_OK;
- retVal=true;
- }
- else if (vKey==UP_ARROW || vKey==OLD_UP_ARROW) scrollBarActionProc(vScrollH,inUpButton);
- else if (vKey==DOWN_ARROW || vKey==OLD_DOWN_ARROW) scrollBarActionProc(vScrollH,inDownButton);
- else if (vKey==PAGE_UP) scrollBarActionProc(vScrollH,inPageUp);
- else if (vKey==PAGE_DOWN) scrollBarActionProc(vScrollH,inPageDown);
- else if (vKey==HOME_KEY || vKey==END_KEY) {
- val=GetCtlValue(vScrollH);
- newVal=(vKey==HOME_KEY) ? GetCtlMin(vScrollH) : GetCtlMax(vScrollH);
- delta=newVal-val;
- SetCtlValue(vScrollH,newVal);
- scrollDelta(vScrollH,val,delta);
- }
- break;
-
- case mouseDown:
- if (infoTEH) {
- where=theEvent->where;
- GlobalToLocal(&where);
- if (partCode=TestControl(vScrollH,where)) {
- if (partCode==inThumb) {
- val=GetCtlValue(vScrollH);
- TrackControl(vScrollH,where,NULL);
- newVal=GetCtlValue(vScrollH);
- if (newVal != val) {
- scrollDelta(vScrollH,val,newVal-val);
- }
- }
- else {
- TrackControl(vScrollH,where,(ProcPtr)scrollBarActionProc);
- }
- }
- }
- break;
-
- case updateEvt:
- if (theDialog==((DialogPtr)(theEvent->message))) {
- SetPort((GrafPtr)theDialog);
- PenNormal();
- GetDItem(theDialog, INFO_ITEM,&itemType,&itemH,&box);
- box.right-=15;
- FrameRect(&box);
- InsetRect(&box,1,1);
- EraseRect(&box);
- InsetRect(&box,3,3);
- if (infoTEH) TEUpdate(&box,infoTEH);
- if (vScrollH) Draw1Control(vScrollH);
- frameButton( theDialog,ITEM_OK, false, false );
- }
- break;
- }
- return(retVal);
- }
-